{% extends 'base.html' %}

{% block title %}测试运行 - EasyTesting{% endblock %}

{% block header %}测试运行{% endblock %}

{% block content %}
<div class="card">
    <div class="card-body">
        {% if project %}
        <div class="alert alert-info mb-4">
            <div class="d-flex align-items-center">
                <i class="bi bi-info-circle-fill me-2"></i>
                <div>
                    <strong>过滤项目:</strong> {{ project.name }}
                    <a href="{% url 'test_run_list' %}" class="btn btn-sm btn-outline-primary ms-3">
                        <i class="bi bi-x-lg"></i>清除过滤
                    </a>
                </div>
            </div>
        </div>
        {% endif %}

        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>名称</th>
                        <th>项目</th>
                        <th>环境</th>
                        <th>状态</th>
                        <th>开始时间</th>
                        <th>结束时间</th>
                        <th>创建人</th>
                        <th class="text-end">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for test_run in test_runs %}
                        <tr>
                            <td>
                                <a href="{% url 'test_run_detail' pk=test_run.pk %}" class="fw-medium text-decoration-none text-dark">
                                    {{ test_run.name }}
                                </a>
                            </td>
                            <td>
                                <a href="{% url 'project_detail' pk=test_run.project.pk %}" class="text-decoration-none">
                                    {{ test_run.project.name }}
                                </a>
                            </td>
                            <td>{{ test_run.environment.name }}</td>
                            <td>
                                {% if test_run.status == 'completed' %}
                                    <span class="badge bg-success">Completed</span>
                                {% elif test_run.status == 'failed' %}
                                    <span class="badge bg-danger">Failed</span>
                                {% elif test_run.status == 'running' %}
                                    <span class="badge bg-primary">Running</span>
                                {% else %}
                                    <span class="badge bg-secondary">Pending</span>
                                {% endif %}
                            </td>
                            <td>{{ test_run.start_time|date:"Y-m-d H:i"|default:"-" }}</td>
                            <td>{{ test_run.end_time|date:"Y-m-d H:i"|default:"-" }}</td>
                            <td>{{ test_run.created_by.username }}</td>
                            <td class="text-end">
                                <a href="{% url 'test_run_detail' pk=test_run.pk %}" class="btn btn-sm btn-outline-primary">
                                    <i class="bi bi-eye"></i>
                                </a>
                                <a href="{% url 'generate_test_run_report' test_run.id %}" class="btn btn-sm btn-info" title="生成报告">
                                   <i class="bi bi-file-earmark-text"></i>
                                </a>
                                <a href="{% url 'test_run_delete' pk=test_run.pk %}" class="btn btn-sm btn-outline-danger">
                                    <i class="bi bi-trash"></i>
                                </a>
                            </td>
                        </tr>
                    {% empty %}
                        <tr>
                            <td colspan="8" class="text-center py-5">
                                <div class="py-5">
                                    <i class="bi bi-play-circle display-4 text-muted mb-3"></i>
                                    <h5>暂无测试运行</h5>
                                    <p class="text-muted">运行测试用例或测试套件</p>
                                </div>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        {% include 'pagination.html' with page_obj=test_runs %}
    </div>
</div>
{% endblock %}
